import { EventManager } from "./EventManager";

/**
 * 事件系统扩展功能
 */
export class EventExtension {
    // 延迟触发事件
    public static delayEmit(eventName: string, delay: number, ...args: any[]): void {
        setTimeout(() => {
            EventManager.getInstance().emit(eventName, ...args);
        }, delay * 1000);
    }

    // 批量监听事件
    public static batchOn(events: { eventName: string, callback: Function, target?: any }[], once?: boolean): void {
        const manager = EventManager.getInstance();
        events.forEach(event => {
            once ? manager.once(event.eventName, event.callback, event.target)
                : manager.on(event.eventName, event.callback, event.target);
        });
    }

    // 事件计数
    private static _eventCount: Map<string, number> = new Map();
    public static countEvent(eventName: string): number {
        const count = this._eventCount.get(eventName) || 0;
        this._eventCount.set(eventName, count + 1);
        return count;
    }
}
